﻿package net.wangit.dev.dataprivilege;

import net.wangit.jdbc.DB;
import net.wangit.util.Checker;
import net.wangit.view.enumeration.EnumerationCache;
import net.wangit.view.page.PageCache;
import net.wangit.view.unit.UnitCache;

public class DataPrivilegeReferenceHelper {

	private static final String SQL_UNIT_REFERENCE = "update UNIT set dpid=? where dpid=?";
	private static final String SQL_ENUMERATION_REFERENCE = "update ENUMCONFIG set dpid=? where dpid=?";

	public DataPrivilegeReferenceHelper() {
	}

	public static void update(DB db, String domain, String oldId, String newId)
			throws Exception {
		if (!Checker.isEmpty(oldId) && !oldId.equals(newId)) {
			db.execute(DataPrivilegeReferenceHelper.SQL_UNIT_REFERENCE,
					new String[] { newId, oldId }, new int[] { 2, 2 });
			db.execute(DataPrivilegeReferenceHelper.SQL_ENUMERATION_REFERENCE,
					new String[] { newId, oldId }, new int[] { 2, 2 });
			UnitCache.clearAll(domain);
			PageCache.clearAll(domain);
			EnumerationCache.clearAll(domain);
		}
	}
}
